#!/usr/bin/env python
from lib.gui.widgets import Container, Button, Slider
from lib.gui.widgets import ActuatorPanel, SettingsPanel
from lib.gui.widgets import ContextBar, WorldWidget, HDynamicBar
from lib.gui.theme import Theme
from main import main

mouse = main.mouse

class Interface(Container):
    def __init__(self):
        """Note that this init overrides Container's one.
        Edit either of them and you must correct the other.
        
        """
        self.theme = Theme(main.config.theme)
        
        self.widgets = []
        
        self._active = None
        self._dragged = set()
        
        self.eventUsers = {'hover': set(),
                           'wheel': set(),
                           'click': set(),
                           'drag': set(),
                           'release': set(),
                           'draw': [],
                           }
        
        self.updateList = []
        
        #WIDGETS
        self.worldWidget = WorldWidget(self, main.world, 0, 48, 800, 352)
        self.contextBar = ContextBar(self, 0, 0, 800, 48)
        
        self.settingsPanel = SettingsPanel(self, 0, 49, 128, 75)
        self.actuatorPanel = ActuatorPanel(self, 0, 125, 210, 300)
        
        self.bar = HDynamicBar(self, 200, 200)
    
    def update(self):
        for widget in self.updateList:
            widget.on_update()
        if mouse.wheel != 0:
            self.on_wheel(mouse.wheel)
        if mouse.checkClicked():
            self.on_click(mouse.x, mouse.y, 0)
        elif mouse.checkReleased():
            self.on_release(mouse.x, mouse.y, 0)
        elif not mouse.checkPressed():
            self.on_hover(mouse.x, mouse.y)
        if self._dragged:
            self.on_drag(mouse.x, mouse.y, mouse.x - mouse.xPrev,
                                           mouse.y - mouse.yPrev, 0)